package com.test.springboot3.springboot3testdemo1.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.annotation.WebInitParam;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： liuziyang
 * @date： 2024/8/2-下午12:37
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
@WebFilter(
    filterName = "javaFilter",
    urlPatterns = "/*",
    initParams = {
      @WebInitParam(name = "name", value = "javaFilter"),
      @WebInitParam(name = "code", value = "123456")
    })
@Slf4j
public class JavaFilter implements Filter {

  /**
   * @param filterConfig
   * @throws ServletException
   */
  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
    log.info("java filter init.");
    final String name = filterConfig.getInitParameter("name");
    final String code = filterConfig.getInitParameter("code");
    log.info("name is {}", name);
    log.info("code is {}", code);
  }

  /**
   * @param servletRequest
   * @param servletResponse
   * @param filterChain
   * @throws IOException
   * @throws ServletException
   */
  @Override
  public void doFilter(
      ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
      throws IOException, ServletException {
    log.info("java filter processing");
    filterChain.doFilter(servletRequest, servletResponse);
  }

  /** */
  @Override
  public void destroy() {
    log.info("java filter destroy.");
  }
}
